// 用setTimeout实现interval
function setTimeoutInterval(fn, time) {
    let timer = null
    let finish = false
    function f() {
        fn()
        if (!finish) {
            timer = setTimeout(f, time)
        }
    }
    timer = setTimeout(f, time)

    return () => {
        clearTimeout(timer)
        finish = true
    }
}

function clearTimeoutInterval(interval) {
    clearTimeout(interval)
}
let times = 0
const clearInterval = setTimeoutInterval(() => {
    times++
    console.log(times)
    if (times === 5) {
        clearInterval()
    }
}, 1000)